package everyday.leetcode;

import java.util.ArrayDeque;
import java.util.Deque;


/**
 * @Author: wenjingyuan
 * @Date: 2022/10/09/19:27
 * @Description:括号的分数
 * https://leetcode.cn/problems/score-of-parentheses/
 */
public class NUm856 {
    public int scoreOfParentheses(String s) {
        Deque<Integer> stack=new ArrayDeque<>();
        stack.addLast(0);
        char[] ret=s.toCharArray();
        for(char i:ret){
            if(i == '('){
                stack.addLast(0);
            }
            else {
                int cur=stack.pollLast();
                stack.addLast(stack.pollLast()+Math.max(2*cur,1));
            }
        }
        return stack.peekLast();
    }
}
